import org.w3c.dom.ls.LSException;

import java.util.Scanner;

/**
 * @author yu
 * @date 2025年04月22日 23:45
 */
public class _09_dp_12_1049lastStoneWeightII {
    public static int lastStoneWeightII(int[] stones) {
        int sum = 0;
        for (int i : stones) {
            sum += i;
        }
        int target = sum >> 1;
        //初始化dp数组
        int[] dp = new int[target + 1];
        for (int i = 0; i < stones.length; i++) {
            //采用倒序
            for (int j = target; j >= stones[i]; j--) {
                //两种情况，要么放，要么不放
                dp[j] = Math.max(dp[j], dp[j - stones[i]] + stones[i]);
            }
        }
        return sum - 2 * dp[target];
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        String[] ss = s.split(" ");
        int[] stones = new int[ss.length];

        for (int i = 0; i < ss.length; i++) {
            stones[i] = Integer.parseInt(ss[i]);
        }
        System.out.println(lastStoneWeightII(stones));

    }
}
